﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ControlChangePass.ascx.cs" Inherits="Usercontrol_ControlChangePass" %>
<script type="text/javascript">
    $().ready(function () {
        //Get thông tin username và password
        $.ajax({
            type: "POST",
            url: '<%=ResolveUrl("~/Webservice/WebService.asmx/GetUserAndPass")%>',
            data: "{'salesp_key':'" + $('#txtMaBaoTro').val() + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                $.each(data.d, function (index, item) {

                    $("#txtUser").val(item.Value);
                    $("#txtOldPass").val(item.Display);

                });
            }
        });

        $("#btChange").click(function () {
            validateForm();
        });

    });
    function validateForm() {
        var txtNewPass = $("#txtNewPass").val();
        var txtRetypePass = $("#txtRetypePass").val();
       

        if (txtNewPass == null || txtNewPass == '') {
            alert('Mật khẩu không được để trống');
            return false;
        }
        else if (txtNewPass != txtRetypePass) {
            alert('Mật khẩu xác nhận không chính xác');
            return false;
        }
        else {
            $.ajax({
                type: "POST",
                url: '<%=ResolveUrl("~/Webservice/WebService.asmx/ChangePass")%>',
                data: "{'PW':'" + $('#txtNewPass').val() + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    alert(data.d);
                }
            });
        }


    }
</script>

<table  id="table1" style="width:450px">
	<tr>
		<td width="141" align="right">Tên &#273;&#259;ng nh&#7853;p</td>
		<td><input id="txtUser" readonly="readonly"></td>
	</tr>
	<tr>
		<td width="141" align="right">M&#7853;t kh&#7849;u c&#361;</td>
		<td><input id="txtOldPass" type="password"></td>
	</tr>
	<tr>
		<td width="141" align="right">M&#7853;t kh&#7849;u m&#7899;i</td>
		<td><input id="txtNewPass" type="password"></td>
	</tr>
	<tr>
		<td width="141" align="right">Xác nh&#7853;n l&#7841;i</td>
		<td><input id="txtRetypePass" type="password"></td>
	</tr>
	<tr>
		<td colspan="2">
		<input type="button" value="&#272;&#7893;i m&#7853;t kh&#7849;u" id="btChange" style="float: right"></td>
	</tr>
</table>
